Component({
  properties: {
    dropDownMenuTitle: {
      type: Array,
      value: [],
    },
    dropDownMenuGradeData: {
      type: Array,
      value: []
    },
    dropDownMenuSubjectData: {
      type: Array,
      value: []
    },
    dropDownMenuDispartData: {
      type: Array,
      value: []
    },
  },
  data: {    
    grade_open: false, // 全部年级
    subject_open: false, // 全部学科
    dispart_open: false, // 全部分册
    shownavindex: '',
    selected_grade_id: 0,
    selected_grade_name: '',
    selected_subject_id: 0,
    selected_subject_name: '', 
    selected_dispart_id: 0,
    selected_dispart_name: '' 
  },
  methods: {
    tapGradeNav: function(e) {
      if (this.data.grade_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
          shownavindex: 0
        })
      } else {
        this.setData({
          grade_open: true,
          subject_open: false,
          dispart_open: false,
          shownavindex: e.currentTarget.dataset.nav
        })
      }
    },
    tapSubjectNav: function(e) {
      if (this.data.subject_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
          shownavindex: 0
        })
      } else {
        this.setData({
          grade_open: false,
          subject_open: true,
          dispart_open: false,
          shownavindex: e.currentTarget.dataset.nav
        })
      }
    },
    tapDispartNav: function(e) {
      if (this.data.dispart_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
          shownavindex: 0
        })
      } else {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: true,
          shownavindex: e.currentTarget.dataset.nav
        })
      }
    },
    showInitGrade(id,title) {
      this.closeHyFilter();
      this.setData({
        selected_grade_id: id,
        selected_grade_name: title
      })
      this.triggerEvent("selectGradeItem", {
        index: 0,
        selectedId: id,
        selectedTitle: title
      })
    },
    selectGradeItem: function(e) {
      var selectedId = e.target.dataset.model.id;
      var selectedTitle = e.target.dataset.model.title;
      this.closeHyFilter();
      this.setData({
        selected_grade_id: selectedId,
        selected_grade_name: selectedTitle
      })
      this.triggerEvent("selectGradeItem", {
        index: this.data.shownavindex,
        selectedId: selectedId,
        selectedTitle: selectedTitle
      })
    },    
    selectSubjectItem: function(e) {
      var selectedId = e.target.dataset.model.id;
      var selectedTitle = e.target.dataset.model.title;
      this.closeHyFilter();
      this.setData({
        selected_subject_id: selectedId,
        selected_subject_name: selectedTitle
      })
      this.triggerEvent("selectSubjectItem", {
        index: this.data.shownavindex,
        selectedId: selectedId,
        selectedTitle: selectedTitle
      })
    },
    selectDispartItem: function(e) {
      var selectedId = e.target.dataset.model.id
      var selectedTitle = e.target.dataset.model.title;
      this.closeHyFilter();
      this.setData({
        selected_dispart_id: selectedId,
        selected_dispart_name: selectedTitle
      })
      this.triggerEvent("selectDispartItem", {
        index: this.data.shownavindex,
        selectedId: selectedId,
        selectedTitle: selectedTitle
      })
    },
    /**关闭筛选 */
    closeHyFilter: function() {
      if (this.data.grade_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
        })
      } else if (this.data.subject_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
        })
      } else if (this.data.dispart_open) {
        this.setData({
          grade_open: false,
          subject_open: false,
          dispart_open: false,
        })
      }
    },
  }  
})